package cn.boysoft.filter;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import cn.boysoft.web.client.JsonClient;


/**
 * @author 付厚俊
 * CreateTime 2013-4-29 下午4:22:18
 */
public class AjaxFilter implements Filter {

	private JsonClient jsonClient = null;
	public void destroy() {
		
	}
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		InputStream in = req.getInputStream();
		byte[] response = jsonClient.send(in);
		res.setCharacterEncoding("UTF-8");
		res.getOutputStream().write(response);
	}

	public void init(FilterConfig config) throws ServletException {
		jsonClient = new JsonClient();
	}

}
